package com.ptszyxx.popose.module.main.user.vm;

import android.app.Application;

import androidx.annotation.NonNull;

import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ptszyxx.popose.common.utils.YBusUtil;
import com.ysg.base.BaseViewModel;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.BaseResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.http.data.entity.user.UserLabelResult;
import com.ysg.utils.YToastUtil;

import java.util.HashMap;
import java.util.Map;

public class UserEditLabelVM extends BaseViewModel<CommonRepository> {
    public int selectNum;

    public UserEditLabelVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onRefreshEvent = new SingleLiveEvent<>();
        public SingleLiveEvent onSelectNumEvent = new SingleLiveEvent<>();
        public SingleLiveEvent onSaveEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onCloseCommand = new BindingCommand(()-> YActivityUtil.getInstance().close(this));
    public BindingCommand onSaveCommand = new BindingCommand(()-> uc.onSaveEvent.call());

    /**
     */
    public void requestLabelList(){
        Map<String, String> map = new HashMap<>();
        HttpUtils.getInstance()
                .data(model.userEditLabelList(map), this,
                        new OnSuccessResult<UserLabelResult>() {
                            @Override
                            public void onSuccessResult(BaseResponse<UserLabelResult> response) {
                                uc.onRefreshEvent.setValue(response.getData());
                            }
                        });
    }
    /**
     */
    public void requestLabel(String ids, String names){
        Map<String, String> map = new HashMap<>();
        map.put("biaoqian", ids);
        HttpUtils.getInstance()
                .data(model.userEditLabel(map), this,
                        new OnSuccessResult<UserLabelResult>() {
                            @Override
                            public void onSuccessResult(BaseResponse<UserLabelResult> response) {
                                YToastUtil.showShort(R.string.success);
                                YActivityUtil.getInstance().close(UserEditLabelVM.this);
                                YBusUtil.label(names);
                            }
                        });
    }

    public void onSelectNum(){
        uc.onSelectNumEvent.call();
    }




}
